home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / win_q_t / trem.zip / SCROLL.C < prev    next >
Text File  |  1991-05-11  |  5KB  |  165 lines

  1. /************************************************************************
  2.  *
  3.  *    Copyright (c) 1991 Microsoft Corporation.  All Rights Reserved.
  4.  *
  5.  *-----------------------------------------------------------------------
  6.  *
  7.  *     Project:  Windows Terminal Example
  8.  *
  9.  *      Module:  scroll.c
  10.  *
  11.  *      Author:  Bryan A. Woodruff (baw)
  12.  *
  13.  *
  14.  *     Remarks:  This module handles all scrolling of the
  15.  *               terminal window
  16.  *
  17.  *   Revisions:  
  18.  *     01.00.000  5/ 9/91 baw   Wrote it
  19.  *
  20.  ************************************************************************/
  21.  
  22. #include "terminal.h"
  23.  
  24. /************************************************************************
  25.  *  BOOL ScrollTerminalVert( HWND hWnd, WORD wScrollCmd, WORD wScrollPos )
  26.  *
  27.  *  Description: 
  28.  *     Scrolls terminal window vertically
  29.  *
  30.  *  Comments:
  31.  *      5/ 8/91  baw  Wrote it
  32.  *
  33.  ************************************************************************/
  34.  
  35. BOOL ScrollTerminalVert( HWND hWnd, WORD wScrollCmd, WORD wScrollPos )
  36. {
  37.    int          nScrollAmt ;
  38.    LOCALHANDLE  hTermInfo ;
  39.    NPTERMINFO   npTermInfo ;
  40.  
  41.    hTermInfo = GetWindowWord( hWnd, GWW_TERMINFO ) ;
  42.    if (NULL == (npTermInfo = (NPTERMINFO) LocalLock( hTermInfo )))
  43.       return ( FALSE ) ;
  44.  
  45.    switch (wScrollCmd)
  46.    {
  47.       case SB_TOP:
  48.          nScrollAmt = -npTermInfo -> yOffset ;
  49.          break ;
  50.  
  51.       case SB_BOTTOM:
  52.          nScrollAmt = npTermInfo -> yScroll - npTermInfo -> yOffset ;
  53.          break ;
  54.  
  55.       case SB_PAGEUP:
  56.          nScrollAmt = -npTermInfo -> ySize ;
  57.          break ;
  58.  
  59.       case SB_PAGEDOWN:
  60.          nScrollAmt = npTermInfo -> ySize ;
  61.          break ;
  62.  
  63.       case SB_LINEUP:
  64.          nScrollAmt = -npTermInfo -> yChar ;
  65.          break ;
  66.  
  67.       case SB_LINEDOWN:
  68.          nScrollAmt = npTermInfo -> yChar ;
  69.          break ;
  70.  
  71.       case SB_THUMBPOSITION:
  72.          nScrollAmt = wScrollPos - npTermInfo -> yOffset ;
  73.          break ;
  74.  
  75.       default:
  76.          LocalUnlock( hTermInfo ) ;
  77.          return ( FALSE ) ;
  78.    }
  79.    if ((npTermInfo -> yOffset + nScrollAmt) > npTermInfo -> yScroll)
  80.       nScrollAmt = npTermInfo -> yScroll - npTermInfo -> yOffset ;
  81.    if ((npTermInfo -> yOffset + nScrollAmt) < 0)
  82.       nScrollAmt = -npTermInfo -> yOffset ;
  83.    ScrollWindow( hWnd, 0, -nScrollAmt, NULL, NULL ) ;
  84.    npTermInfo -> yOffset = npTermInfo -> yOffset + nScrollAmt ;
  85.    SetScrollPos( hWnd, SB_VERT, npTermInfo -> yOffset, TRUE ) ;
  86.  
  87.    LocalUnlock( hTermInfo ) ;
  88.    return ( TRUE ) ;
  89.  
  90. } /* end of ScrollTerminalVert() */
  91.  
  92. /************************************************************************
  93.  *  BOOL ScrollTerminalHorz( HWND hWnd, WORD wScrollCmd, WORD wScrollPos )
  94.  *
  95.  *  Description: 
  96.  *     Scrolls terminal window horizontally
  97.  *
  98.  *  Comments:
  99.  *      5/ 8/91  baw  Wrote it
  100.  *
  101.  ************************************************************************/
  102.  
  103. BOOL ScrollTerminalHorz( HWND hWnd, WORD wScrollCmd, WORD wScrollPos )
  104. {
  105.    int          nScrollAmt ;
  106.    LOCALHANDLE  hTermInfo ;
  107.    NPTERMINFO   npTermInfo ;
  108.  
  109.    hTermInfo = GetWindowWord( hWnd, GWW_TERMINFO ) ;
  110.    if (NULL == (npTermInfo = (NPTERMINFO) LocalLock( hTermInfo )))
  111.       return ( FALSE ) ;
  112.  
  113.    switch (wScrollCmd)
  114.    {
  115.       case SB_TOP:
  116.          nScrollAmt = -npTermInfo -> xOffset ;
  117.          break ;
  118.  
  119.       case SB_BOTTOM:
  120.          nScrollAmt = npTermInfo -> xScroll - npTermInfo -> xOffset ;
  121.          break ;
  122.  
  123.       case SB_PAGEUP:
  124.          nScrollAmt = -npTermInfo -> xSize ;
  125.          break ;
  126.  
  127.       case SB_PAGEDOWN:
  128.          nScrollAmt = npTermInfo -> xSize ;
  129.          break ;
  130.  
  131.       case SB_LINEUP:
  132.          nScrollAmt = -npTermInfo -> xChar ;
  133.          break ;
  134.  
  135.       case SB_LINEDOWN:
  136.          nScrollAmt = npTermInfo -> xChar ;
  137.          break ;
  138.  
  139.       case SB_THUMBPOSITION:
  140.          nScrollAmt = wScrollPos - npTermInfo -> xOffset ;
  141.          break ;
  142.  
  143.       default:
  144.          LocalUnlock( hTermInfo ) ;
  145.          return ( FALSE ) ;
  146.    }
  147.    if ((npTermInfo -> xOffset + nScrollAmt) > npTermInfo -> xScroll)
  148.       nScrollAmt = npTermInfo -> xScroll - npTermInfo -> xOffset ;
  149.    if ((npTermInfo -> xOffset + nScrollAmt) < 0)
  150.       nScrollAmt = -npTermInfo -> xOffset ;
  151.    ScrollWindow( hWnd, -nScrollAmt, 0, NULL, NULL ) ;
  152.    npTermInfo -> xOffset = npTermInfo -> xOffset + nScrollAmt ;
  153.    SetScrollPos( hWnd, SB_HORZ, npTermInfo -> xOffset, TRUE ) ;
  154.  
  155.    LocalUnlock( hTermInfo ) ;
  156.    return ( TRUE ) ;
  157.  
  158. } /* end of ScrollTerminalHorz() */
  159.  
  160.  
  161. /************************************************************************
  162.  * End of File: scroll.c
  163.  ************************************************************************/
  164.  
  165.